package com.ysy.logistics.service.supplier.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysy.logistics.entities.oam.LoginLog;
import com.ysy.logistics.entities.supplier.SupGoods;
import com.ysy.logistics.entities.supplier.dto.SupGoodsDto;
import com.ysy.logistics.entities.supplier.dto.SupplierDto;
import com.ysy.logistics.entities.supplier.vo.SupplierQueryVO;
import com.ysy.logistics.mapper.supplier.SupGoodsMapper;
import com.ysy.logistics.service.supplier.SupGoodsService;
import com.ysy.logistics.util.PageInfo;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * @ClassDescription:
 * @Author:姚斯羽
 * @Create:2025/3/25 14:26
 **/
@Service
public class SupGoodsServiceImpl extends ServiceImpl<SupGoodsMapper, SupGoods> implements SupGoodsService {

    @Resource
    private SupGoodsMapper supGoodsMapper;

    @Override
    public Page<SupGoodsDto> listByPage(PageInfo<SupplierQueryVO> pageInfo) {
        //查询出供应商列表
        return supGoodsMapper.listByPage(pageInfo.getPage(), pageInfo.getCriteria());
    }

    @Override
    public boolean removeBySupId(String id) {
        if (StringUtils.isBlank(id)) {
            return false;
        }
        LambdaQueryWrapper<SupGoods> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SupGoods::getSupId, id);
        return this.remove(queryWrapper);
    }

    @Override
    public Page<SupGoods> listSupGoodsPage(PageInfo<SupGoods> pageInfo) {
        //获取参数

        LambdaQueryWrapper<SupGoods> lqw = new LambdaQueryWrapper();
        SupGoods criteria = pageInfo.getCriteria();
        if (StringUtils.isNotBlank(criteria.getSupId())) {
            lqw.eq(SupGoods::getSupId, criteria.getSupId());
        }
        if (StringUtils.isNotBlank(criteria.getName())) {
            lqw.like(SupGoods::getName, criteria.getName());
        }
        if (StringUtils.isNotBlank(criteria.getType())) {
            lqw.eq(SupGoods::getType, criteria.getType());
        }

        lqw.eq(SupGoods::getStatus, 0);

        return supGoodsMapper.selectPage(pageInfo.getPage(), lqw);
    }
}
